<?php
// +----------------------------------------------------------------------
// | webhooks
// +----------------------------------------------------------------------
// | Author: King east <1207877378@qq.com>
// +----------------------------------------------------------------------


namespace app\admin\controller;


use app\common\model\Admin;
use think\Controller;

class AuthController extends Controller
{
    public function login()
    {
        $form = $this->request->post();
        $err = $this->validate($form, [
            'username'=>'require|max:30',
            'password'=>'require|max:50'
        ]);
        if ($err !== true) {
            return json(['error'=>$err]);
        }

        /**
         * @var Admin $admin
         */
        $admin = Admin::where('username', $form['username'])->find();
        if (!$admin) {
            return json(['error'=>"登陆账号“{$form['username']}”不存在"]);
        }
        if (!$admin->hasPassword($form['password'])) {
            return json(['error'=>'登陆密码错误']);
        }
        $admin->login();


        return json(['status'=>1]);

    }

}